import request from '@/utils/request'


import type { ApiResponse, PageResult } from './types'
import type { LoginLog, LoginLogQuery, LoginLogExport } from '@/types/loginLog'

const api = {
    LoginLog: '/loginLog'
}

/**
 * 分页查询登录日志列表
 * @param params 查询参数
 * @returns 登录日志列表
 */
export function getLoginLogPageList(params?: LoginLogQuery) {
    return request.get<ApiResponse<PageResult<LoginLog>>>(`${api.LoginLog}/list`, { params })
}

/**
 * 批量删除登录日志
 * @param ids 日志ID数组
 * @returns 操作结果
 */
export function batchDeleteLoginLog(ids: number[]) {
    return request.delete<ApiResponse>(`${api.LoginLog}/batch`, {
        data: ids
    })
}

/**
 * 清空登录日志
 * @returns 操作结果
 */
export function clearLoginLog() {
    return request.delete<ApiResponse>(`${api.LoginLog}/clear`)
}

/**
 * 导出登录日志
 * @param params 导出参数
 * @returns 文件流
 */
export function exportLoginLog(params: LoginLogExport) {
    return request.get(`${api.LoginLog}/export`, {
        params,
        responseType: 'blob',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    })
} 